﻿package net.ycsk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;

public class Main extends Activity implements OnItemSelectedListener, OnItemClickListener
{
    private static final int REQUEST_CODE=1;
	private static String[] data = new String[]{ 
			"news",
		"users"
	};

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id)
	{
		Intent intent = new Intent();
		switch (position) {
		 		 case 0: 
		 	intent.setClass(Main.this,newsList.class); 
		 	break; 
		 case 1: 
		 	intent.setClass(Main.this,usersList.class); 
		 	break; 

		}
		intent.putExtra("str", "首页activity");
		//startActivity(intent);//无返回值的调用,启动一个明确的activity
		startActivityForResult(intent, REQUEST_CODE);	
	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position,long id)
	{
		Log.d("itemselected", "select " + position + " item");				
	}

	@Override
	public void onNothingSelected(AdapterView<?> parent)
	{
		Log.d("nothingselected", "nothing selected");	
	}
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{  
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		ListView lvCommonListView = (ListView) findViewById(R.id.lvCommonListView);

		ArrayAdapter<String> aaData = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, data);
				
		lvCommonListView.setAdapter(aaData);		
		lvCommonListView.setSelection(6);		
		lvCommonListView.setOnItemClickListener(this);
		lvCommonListView.setOnItemSelectedListener(this);
	}

}
